//
//  AYMCaseMangerCell.m
//  QuickCure
//
//  Created by guo3920591 on 16/5/9.
//  Copyright © 2016年 ayumi. All rights reserved.
//

#import "AYMCaseMangerCell.h"
#import "AYMCaseManger.h"

@interface AYMCaseMangerCell()
@property(nonatomic,weak)UIImageView *linerb1;
@property(nonatomic,weak)UIImageView *linerb2;
@property(nonatomic,weak)UIImageView *line;
@property(nonatomic,weak)UIButton *imgButton;
@property(nonatomic,weak)UILabel *timeLabel;
@property(nonatomic,weak)UILabel *diseaseLabel;
@property(nonatomic,weak)UILabel *baseCase;
@property(nonatomic,weak)UILabel *detaillab;
@end
@implementation AYMCaseMangerCell
//重写模型属性
-(void)setModel:(AYMCaseManger *)model{
    _model = model;
    
    self.diseaseLabel.text = model.caseName;
    self.baseCase.text = model.baseName;
    self.detaillab.text = model.descriptionName;
    
    if (model.pathString==nil || [model.pathString isEqualToString:@""]) {
        [self.imgButton setBackgroundImage:[UIImage imageNamed:@"compose_pic_add_highlighted"] forState:UIControlStateNormal];
    }else{
        [self.imgButton setBackgroundImage:[UIImage imageWithContentsOfFile: [ NSHomeDirectory() stringByAppendingString:[NSString stringWithFormat:@"/Documents/%@",model.pathString]]] forState:UIControlStateNormal];
    }
    
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        UIImageView *linerb1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"illness_rb_img_sel.png"]];
        UIImageView *linerb2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"illness_rb_img_sel.png"]];
        UIImageView *line = [[UIImageView alloc] init];
        line.backgroundColor = [UIColor darkGrayColor];
        [self.contentView addSubview:linerb1];
        [self.contentView addSubview:linerb2];
        [self.contentView addSubview:line];
        UIButton *imgButton =[[UIButton alloc] init];
        [imgButton setBackgroundImage:[UIImage imageNamed:@"compose_pic_add_highlighted"] forState:UIControlStateNormal];
        self.imgButton = imgButton;
        imgButton.userInteractionEnabled = NO;
        [self.contentView addSubview:imgButton];
        
        UILabel *timeLabel =[[UILabel alloc] init];
        timeLabel.font = [UIFont systemFontOfSize:14];
        
        timeLabel.textColor = [UIColor lightGrayColor];
        
        [self.contentView addSubview:timeLabel];
        
        NSDate *now = [NSDate date];
        
        NSDateFormatter *fomatter = [[NSDateFormatter alloc] init];
        
        fomatter.dateFormat = @"yy-MM-dd HH:mm:ss";
        
        NSString *str = [fomatter stringFromDate:now];
        
        timeLabel.text = str;
        
        UILabel *diseaseLabel =  [[UILabel alloc] init];
        diseaseLabel.font = [UIFont systemFontOfSize:14];
        UILabel *baseCase = [[UILabel alloc] init];
        baseCase.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:diseaseLabel];
        [self.contentView addSubview:baseCase];
        
        self.diseaseLabel = diseaseLabel;
        self.baseCase = baseCase;
        
        UILabel *detailLabel = [[UILabel alloc] init];
        detailLabel.font = [UIFont systemFontOfSize:14];
        detailLabel.numberOfLines = 0;
        detailLabel.textColor = [UIColor lightGrayColor];
        detailLabel.text = @"labelasSS";
        [self.contentView addSubview:detailLabel];
        self.detaillab = detailLabel;
        
        [linerb2 makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.left).offset(10);
            make.bottom.equalTo(self.bottom);
            
        }];
        
        [line makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(linerb2.centerX);
            make.bottom.equalTo(linerb2.top);
            make.width.equalTo(1);
            make.height.equalTo(90);
            
        }];
        
        [linerb1 makeConstraints:^(MASConstraintMaker *make) {
            
            make.left.equalTo(self.left).offset(10);
            make.bottom.equalTo(line.top);
        }];
        
        
        [timeLabel makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(line.top);
            make.left.equalTo(linerb1.right).offset(10);
            
        }];
        
        [imgButton makeConstraints:^(MASConstraintMaker *make) {
            
            make.top.equalTo(timeLabel.bottom);
            make.left.equalTo(timeLabel.left);
            
            make.size.equalTo(CGSizeMake(70, 70));
            
        }];
        
        
        [diseaseLabel makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(imgButton.right).offset(10);
            make.top.equalTo(imgButton.top).offset(3);
            
        }];
        
        [baseCase makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(diseaseLabel.right).offset(15);
            make.centerY.equalTo(diseaseLabel.centerY);
            
        }];
        
        [detailLabel makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(diseaseLabel.left);
            make.top.equalTo(diseaseLabel.bottom).offset(15);
            make.width.equalTo(180);
            
        }];
        
        
    }
    
    return self;
}
@end
